Linetracing program (Assembly)
This program is for the August 2015 IRO (China), using Aaron's arduino robot. /* Copyright © 2015 Calvin Ng This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. See > for the full license. Contact at calvinforum@rocketmail.com */ void setup() { asm volatile( "SBI %DIRAnalog, %PNA0 \n\t" "SBI %DIR813, %PN13 \n\t" "CBI %DIR813, %PN12 \n\t" "SBI %DIR813, %PN8 \n\t" "SBI %DIR813, %PN9 \n\t" "SBI %DIR813, %PN10 \n\t" "SBI %DIR813, %PN11 \n\t" "CBI %DIR07, %PN5 \n\t" "CBI %DIRAnalog, %PNA1 \n\t" :: DIR07 "I" (_SFR_IO_ADDR(DDRD)), DIR813 "I" (_SFR_IO_ADDR(DDRB)), PN8 "I" (DDB0), PN9 "I" (DDB1), PN10 "I" (DDB2), PN11 "I" (DDB3), PN0 "I" (DDD0), PN5 "I" (DDD5), PN13 "I" (DDB5), PN12 "I" (DDB4), DIRAnalog "I" (_SFR_IO_ADDR(DDRC)), PNA0 "I" (DDC0), PNA1 "I" (DDC1) ); } void loop() { asm volatile( "CBI %OUTAnalog, %PNA0 \n\t" "CBI %OUT813, %PN13 \n\t" "CALL WaitMainSwitch \n\t" "Main: \n\t" //if-else loop starts here "SBIC %INAnal, %PNA1 \n\t" "RJMP sense1 \n\t" "SBIC %IN07, %PN4 \n\t" "RJMP sense7 \n\t" "SBIC %IN07, %PN2 \n\t" "RJMP sense2 \n\t" "SBIC %IN07, %PN3 \n\t" "RJMP sense6 \n\t" "SBIC %IN07, %PN7 \n\t" "RJMP sense3 \n\t" "SBIC %IN07, %PN6 \n\t" "RJMP sense5 \n\t" "CALL MoveFwd \n\t" "RJMP Main \n\t" "sense3: \n\t" "CALL SwvLeft \n\t" "RJMP Main \n\t" "sense5: \n\t" "CALL SwvRight \n\t" "RJMP Main \n\t" "sense1: \n\t" "CALL TurnLeft \n\t" "SBIS %IN07, %PN5 \n\t" "SBIS %IN07, %PN6 \n\t" "RJMP sense1 \n\t" "RJMP Main \n\t" "sense7: \n\t" "CALL TurnRight \n\t" "SBIS %IN07, %PN5 \n\t" "SBIS %IN07, %PN7 \n\t" "RJMP sense7 \n\t" "RJMP Main \n\t" "sense2: \n\t" "CALL HSwvL \n\t" "RJMP Main \n\t" "sense6: \n\t" "CALL HSwvR \n\t" "RJMP Main \n\t" //end of if-else loop "WaitMainSwitch: \n\t"//Wait until main switch start "SBIS %IN813, %PN12 \n\t" "RET \n\t" "RJMP WaitMainSwitch \n\t" :: OUT813 "I" (_SFR_IO_ADDR(PORTB)), OUT07 "I" (_SFR_IO_ADDR(PORTD)), PN8 "I" (PORTB0), PN9 "I" (PORTB1), PN10 "I" (PORTB2), PN11 "I" (PORTB3), IN07 "I" (_SFR_IO_ADDR(PIND)), PN5 "I" (PIND5), PN0 "I" (PORTD0), PN13 "I" (PORTB5), OUTAnalog "I" (_SFR_IO_ADDR(PORTC)), PNA0 "I" (PORTC0), IN813 "I" (_SFR_IO_ADDR(PINB)), PN12 "I" (PINB4), PN6 "I" (PIND6), PN7 "I" (PIND7), INP07 "a" (PIND), PN4 "I" (PIND4), PN2 "I" (PIND2), PN3 "I" (PIND3), INAnal "I" (_SFR_IO_ADDR(PINC)), PNA1 "I" (PINC1) ); asm volatile( "MoveFwd: \n\t" "SBI %OUT813, %PN8 \n\t" "SBI %OUT813, %PN11 \n\t" :: OUT813 "I" (_SFR_IO_ADDR(PORTB)), PN8 "I" (PORTB0), PN11 "I" (PORTB3) ); analogWrite(9, 100); analogWrite(10, 100); asm volatile( "RET" :: ); asm volatile( "SwvLeft: \n\t" "SBI %OUT813, %PN8 \n\t" "SBI %OUT813, %PN11 \n\t" :: OUT813 "I" (_SFR_IO_ADDR(PORTB)), PN8 "I" (PORTB0), PN11 "I" (PORTB3) ); analogWrite(9, 110); analogWrite(10, 60); asm volatile( "RET" :: ); asm volatile( "SwvRight: \n\t" "SBI %OUT813, %PN8 \n\t" "SBI %OUT813, %PN11 \n\t" :: OUT813 "I" (_SFR_IO_ADDR(PORTB)), PN8 "I" (PORTB0), PN11 "I" (PORTB3) ); analogWrite(9, 60); analogWrite(10, 110); asm volatile( "RET" :: ); asm volatile( "TurnRight: \n\t" "CBI %OUT813, %PN8 \n\t" "SBI %OUT813, %PN11 \n\t" :: OUT813 "I" (_SFR_IO_ADDR(PORTB)), PN8 "I" (PORTB0), PN11 "I" (PORTB3) ); analogWrite(9, 50); analogWrite(10, 70); asm volatile( "RET" :: ); asm volatile( "TurnLeft: \n\t" "SBI %OUT813, %PN8 \n\t" "CBI %OUT813, %PN11 \n\t" :: OUT813 "I" (_SFR_IO_ADDR(PORTB)), PN8 "I" (PORTB0), PN11 "I" (PORTB3) ); analogWrite(9, 70); analogWrite(10, 50); asm volatile( "RET" :: ); asm volatile( "HSwvR: \n\t" "SBI %OUT813, %PN8 \n\t" "SBI %OUT813, %PN11 \n\t" :: OUT813 "I" (_SFR_IO_ADDR(PORTB)), PN8 "I" (PORTB0), PN11 "I" (PORTB3) ); analogWrite(9, 30); analogWrite(10, 125); asm volatile( "RET" :: ); asm volatile( "HSwvL: \n\t" "SBI %OUT813, %PN8 \n\t" "SBI %OUT813, %PN11 \n\t" :: OUT813 "I" (_SFR_IO_ADDR(PORTB)), PN8 "I" (PORTB0), PN11 "I" (PORTB3) ); analogWrite(9, 125); analogWrite(10, 30); asm volatile( "RET" :: ); } Category:Assembly Category:Arduino Category:Programming Category:Not Lego